using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// Correspond to the Vn node declarator in the grammar(AnsiC).
    /// </summary>
    internal partial class Vndeclarator : IFullFormatter {
        // [129]=declarator : pointer direct_declarator ;
        // [130]=declarator : direct_declarator ;


        private readonly TokenRange _scope;
        private readonly Vnpointer? r1;
        private readonly Vndirect_declarator r0;

        public TokenRange Scope => _scope;

        public void Format(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        public void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
            if (r1 != null) {
                context.PrintBlanksAnd(r1, preConfig, writer);
                var config = new BlankConfig();
                context.PrintCommentsBetween(r1, r0, config, writer);
                context.PrintBlanksAnd(r0, config, writer);
            }
            else {
                context.PrintBlanksAnd(r0, preConfig, writer);
            }
        }

        public IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        internal Vndeclarator(Vnpointer? r1, Vndirect_declarator r0) {
            this.r1 = r1;
            this.r0 = r0;
            if (r1 != null) { this._scope = new TokenRange(r1, r0); }
            else { this._scope = new TokenRange(r0); }
        }

    }
}
